package cn.newhopedairy.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * @author Neo.Li
 * @date 2021-01-1316:44
 */
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    private static final String[] excludedAuthPages = {
            "/swagger-ui/**",
            "/swagger-resources/**",
            "/v3/api-docs"
    };

    @Override
    public void configure(WebSecurity web) throws Exception {
        // WebSecurity绕过了Security的filter，适合于配置静态资源、不需要权限验证的三方回调等
        web.ignoring().antMatchers(excludedAuthPages);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                .oauth2ResourceServer()
                .jwt();
    }
}
